/* 
 * Copyright (c) 2011, Raincity Games LLC
 * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
 */

#include "Stream.h"


using namespace std;
using namespace Gdk;

#define COMPRESSION_BUFFER_SIZE         65536                   // Size of temp buffers used for compression

// *****************************************************************
/// @brief
///     Default Constructor
// *****************************************************************
Stream::Stream()
{
}

// *****************************************************************
/// @brief
///     Destructor
// *****************************************************************
Stream::~Stream()
{
}

// *****************************************************************
/// @brief
///     Reads a char* string from the stream
/// @remarks
///     char* strings are stored as a 2-byte string length, followed by
///     the actual character data of the string, NOT including the NULL terminator.
// *****************************************************************
string Stream::ReadString()
{
        // Read the string length
        string::size_type length = ReadUInt16();
        string result;
        result.reserve(length + 1);

        // Read the string characters
        for(string::size_type i=0; i<length; i++) 
        { 
                char c = ReadUInt8();
                result.push_back(c); 
        }

        return result;
}

// *****************************************************************
/// @brief
///     Writes a char* string to the stream
/// @remarks
///     char* strings are stored as a 2-byte string length, followed by
///     the 8-bit characters of the string, NOT including the NULL terminator.
// *****************************************************************
void Stream::WriteString(const char* value)
{
        // Add the string length
        UInt16 length = strlen(value);
        WriteUInt16(length);
        
        // Add the string characters
        Write((Byte*)value, length);
}

// *****************************************************************
/// @brief
///     Decompresses this stream into another stream
/// @param destination
///     Stream to where the decompressed data is to be written
/// @param compressionType
///     Which compression type the data is compressed with
// *****************************************************************
bool Stream::Decompress(Stream* destination, CompressionType::Enum compressionType)
{
  return true;
}